ajax = """var FORK=FORK||{};FORK.Ajax=function(method,url,options){this.setOptions(options);this.method=method.toUpperCase();this.request=FORK.Ajax.newXMLHttpRequest();if(!this.request){return true;}
this.aborted=false;var self=this;if(this.options.timeout){this.timer=setTimeout(function(){self.onTimeout();},this.options.timeout);}
this.request.onreadystatechange=function(){self.onReadyStateChange();};this.body=this.options.body||{};this.setMethod();this.body=(function(oBody){var aBody=[];for(var p in oBody){aBody.push(encodeURIComponent(p)+"="+encodeURIComponent(oBody[p]));}
return((aBody.length>0)?aBody.join("&"):null);})(this.body);var serialization=null;if(this.options.form){serialization=FORK.Ajax.serializeForm(this.options.form);}
if(this.body&&serialization){this.body=serialization+"&"+this.body;}else if(serialization){this.body=serialization;}
if(this.method==='GET'){if(this.body){url=url+(url.match(/\?/)?'&':'?')+this.body;}
this.body=null;}
this.request.open(this.method,url,true);if(this.method==="POST"){this.request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");}
if(this.options.headers){for(p in this.options.headers){this.request.setRequestHeader(p,this.options.headers[p]);}}
this.request.send(this.body);};FORK.Ajax.prototype.setOptions=function(options){this.options=options||{};};FORK.Ajax.prototype.setMethod=function(){if(this.method==='GET'){this.body._uniqueId=(new Date()).getTime()+""+FORK.Ajax.transactionId++;}};FORK.Ajax.transactionId=0;FORK.Ajax.newXMLHttpRequest=function(){var fs=[function(){return new ActiveXObject("Microsoft.XMLHTTP");},function(){return new ActiveXObject("Msxml2.XMLHTTP");},function(){return new ActiveXObject("Msxml2.XMLHTTP.3.0");},function(){return new XMLHttpRequest();}];for(var i=fs.length;i--;){try{var r=fs[i]();if(r){FORK.Ajax.newXMLHttpRequest=fs[i];return r;}}catch(e){}}
(FORK.Ajax.newXMLHttpRequest=function(){return null;})();};FORK.Ajax.serializeForm=function(f){if(typeof f=='string'){f=document.getElementById(f)||document.forms[f];}
var els=f.elements,cereal=[];function add(n,v){cereal.push(encodeURIComponent(n)+"="+encodeURIComponent(v));}
for(var i=0,ilen=els.length;i<ilen;i++){var el=els[i];if(!el.disabled){switch(el.type){case'text':case'password':case'hidden':case'textarea':add(el.name,el.value);break;case'select-one':if(el.selectedIndex>=0){add(el.name,el.options[el.selectedIndex].value);}
break;case'select-multiple':for(var j=0,jlen=el.options.length;j<jlen;j++){var opt=el.options[j];if(opt.selected){add(el.name,opt.value);}}
break;case'checkbox':case'radio':if(el.checked){add(el.name,el.value);}
break;}}}
if(this.button){add(this.button.name,this.button.value);this.button=null;}
return((cereal.length>0)?cereal.join("&"):null);};FORK.Ajax.setButton=function(el){this.button={name:el.name,value:el.value};};FORK.Ajax.prototype.doCallback=function(sMethod){if(this.options.scope){this.options[sMethod].call(this.options.scope,this.request,this.options.argument);}else{this.options[sMethod](this.request,this.options.argument);}};FORK.Ajax.prototype.onReadyStateChange=function(){if(!this.aborted&&this.request.readyState===4){if(this.timer){clearTimeout(this.timer);}
if(this.request){this.handleReadyState4();}
this.request=null;}};FORK.Ajax.prototype.handleReadyState4=function(){var request=this.request,options=this.options;var status;try{status=request.status;}catch(e){status=13030;}
if(status==12002||status==12029||status==12030||status==12031||status==12152||status==13030){this.request={status:0,statusText:"communication failure",argument:options.argument};}
if(options.before){this.doCallback("before");}
this.status=status;this.middleCallback();if(options.after){this.doCallback("after");}};FORK.Ajax.prototype.middleCallback=function(){if(this.options["on"+status]){this.doCallback("on"+status);}else if(this.status>=200&&this.status<300&&this.options.onSuccess){this.doCallback("onSuccess");}else if((this.status<200||this.status>=300)&&this.options.onFailure){this.doCallback("onFailure");}else if(this.options.onComplete){this.doCallback("onComplete");}};FORK.Ajax.prototype.abort=function(){this.aborted=true;this.request.abort();this.request=null;};FORK.Ajax.prototype.onTimeout=function(){this.aborted=true;this.request.abort();this.handleTimeout();this.request=null;};FORK.Ajax.prototype.handleTimeout=function(){if(this.options.before){this.doCallback("before");}
if(this.options.onTimeout){this.doCallback("onTimeout");}
if(this.options.after){this.doCallback("after");}};FORK.Ajax.isSupported=(function(){var en=false,x;try{if(typeof(function(){}).call==="function"&&(x=FORK.Ajax.newXMLHttpRequest())&&x.readyState===0){en=true;}}catch(e){en=false;}
try{if(!x.setRequestHeader){en=false;}}catch(e){}
function cannotPost(){var xhr=new XMLHttpRequest();try{xhr.send("asdf");}catch(e){if(-1!==e.toString().indexOf("Could not convert JavaScript argument arg 0 [nsIXMLHttpRequest.send]")){return true;}}
return false;}
if(this.XMLHttpRequest&&cannotPost()){en=false;}
return function(){return en;};})();"""

main = ""

ajaxRails = """FORK.Ajax.prototype.originalSetOptions=FORK.Ajax.prototype.setOptions;FORK.Ajax.prototype.setOptions=function(options){options=options||{};options.headers=options.headers||{};options.headers.Accept=options.headers.Accept||'text/javascript,application/javascript,text/html,application/json,application/xml,text/xml,*/*';this.options=options;};FORK.Ajax.prototype.originalSetMethod=FORK.Ajax.prototype.setMethod;FORK.Ajax.prototype.setMethod=function(){if(this.method!=='GET'&&this.method!=='POST'){this.body._method=this.method;this.options.headers["X-PIGGYBACK-METHOD"]=this.method;this.method="POST";}else{this.originalSetMethod();}};FORK.Ajax.prototype.originalMiddleCallback=FORK.Ajax.prototype.middleCallback;FORK.Ajax.prototype.middleCallback=function(){var rpc=false;try{rpc=this.request.getResponseHeader("Content-Type").toLowerCase().match(/(text|application)\/javascript/)||this.request.getAllResponseHeaders().toLowerCase().match(/content-type\:\s(text|application)\/javascript/);}catch(e){}
if(rpc){FORK.Ajax.evalScript(this.request.responseText);}else{this.originalMiddleCallback();}};FORK.Ajax.evalScript=function(){eval(arguments[0]);};FORK.Ajax.isSupported=(function(){var en=(FORK.Ajax.isSupported&&FORK.Ajax.isSupported());if(en&&this.opera&&this.opera.version&&this.opera.version()<8.54){en=false;}
return function(){return en;};})();"""
